{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    {if condition="$id eq 0"}
    <div class="layui-form-bar">
        <h3 class="pb-3">新增类型</h3>
    </div>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray">字段类型<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required" class="layui-input">
                        <option value=""></option>
                        <option value="table">表类型</option>
                        <option value="op">文印类型</option>
                        <option value="paper">纸类型</option>
                    </select>
                </div>
            </td>
            <td class="layui-td-gray">字段名称<font>*</font></td>
            <td>
                <input type="text" name="name" lay-verify="required" placeholder="请输入名称" lay-reqText="请输入名称" autocomplete="off" class="layui-input">
            </td>
        </tr>
    </table>
    {else/}
    <div class="layui-form-bar">
        <h3 class="pb-3">编辑类型</h3>
    </div>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray">表类型<font>*</font></td>
            <td>
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$record.id}">
                    <select name="kind" lay-verify="required" class="layui-input">
                        <option value=""></option>
                        <option value="table" {eq name="$record.type" value="table" }selected{/eq}>表类型</option>
                        <option value="op" {eq name="$record.type" value="op" }selected{/eq}>文印类型</option>
                        <option value="paper" {eq name="$record.type" value="paper" }selected{/eq}>纸类型</option>
                    </select>
                </div>
            </td>
            <td class="layui-td-gray">字段名称<font>*</font></td>
            <td>
                <input type="text" name="name" lay-verify="required" value="{$record.name}" autocomplete="off" class="layui-input">
            </td>
        </tr>
    </table>
    {/if}
    <div class="py-3">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    function gouguInit() {
        let form = layui.form,tool=layui.tool;

        //监听提交
        form.on('submit(webform)', function (data) {
            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    parent.layui.pageTable.reload();
                    setTimeout(function () {
                        parent.layui.tool.close();
                    }, 1000);
                }
            };
            tool.post("/admin/data/add_config", data.field, callback);
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->